using System;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
namespace BMC.ARSystem
{
	internal abstract class DataLoader
	{
		private string _dataFileName;
		public event BeginLoadingEventHandler _beginLoadingEH
		{
			[MethodImpl(32)]
			add
			{
				this._beginLoadingEH = (BeginLoadingEventHandler)Delegate.Combine(this._beginLoadingEH, value);
			}
			[MethodImpl(32)]
			remove
			{
				this._beginLoadingEH = (BeginLoadingEventHandler)Delegate.Remove(this._beginLoadingEH, value);
			}
		}
		public event LoadDataLineEventHandler _loadDataLineEventEH
		{
			[MethodImpl(32)]
			add
			{
				this._loadDataLineEventEH = (LoadDataLineEventHandler)Delegate.Combine(this._loadDataLineEventEH, value);
			}
			[MethodImpl(32)]
			remove
			{
				this._loadDataLineEventEH = (LoadDataLineEventHandler)Delegate.Remove(this._loadDataLineEventEH, value);
			}
		}
		public event AfterLoadedEventHandler _afterLoadedEH
		{
			[MethodImpl(32)]
			add
			{
				this._afterLoadedEH = (AfterLoadedEventHandler)Delegate.Combine(this._afterLoadedEH, value);
			}
			[MethodImpl(32)]
			remove
			{
				this._afterLoadedEH = (AfterLoadedEventHandler)Delegate.Remove(this._afterLoadedEH, value);
			}
		}
		public DataLoader(string dataFileName)
		{
			this._dataFileName = dataFileName;
		}
		public void Load()
		{
			Assembly assembly = Assembly.GetAssembly(typeof(ARControlStruct));
			assembly.GetManifestResourceNames();
			Stream manifestResourceStream = assembly.GetManifestResourceStream(this._dataFileName);
			if (this._beginLoadingEH != null)
			{
				this._beginLoadingEH(this, new BeginLoadingEventArgs());
			}
			try
			{
				using (StreamReader streamReader = new StreamReader(manifestResourceStream))
				{
					string text;
					while ((text = streamReader.ReadLine()) != null)
					{
						text = text.Trim();
						if (text.get_Length() != 0 && !text.StartsWith("#") && this._loadDataLineEventEH != null)
						{
							this._loadDataLineEventEH(this, new LoadDataLineEventArgs(text));
						}
					}
				}
			}
			catch (Exception ex)
			{
				Console.WriteLine("The file could not be read:");
				Console.WriteLine(ex.get_Message());
			}
			manifestResourceStream.Close();
			if (this._afterLoadedEH != null)
			{
				this._afterLoadedEH(this, new AfterLoadedEventArgs());
			}
		}
	}
}
